/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cosc617_blackteam;

import java.util.ArrayList;

/**
 *
 * @author Anton
 *
 * Edited by Laura 4/9/13 adding comment and menu functionality
 */
public class InfoAggregator implements I_InfoAggregator {

    private CommentCollection comments;
    private OrderCollections orders;
    private Menu menu;
    private int numCustomersServed;
    private int numItemsOrdered;
    private TableCollections tables;
    private TabCollection tabs;
    private I_SeatingStrategy seatingStrat;
    private I_CookingStrategy cookingStrat;

    public InfoAggregator() {
        comments = new CommentCollection();
        menu = new Menu();
        menu.generateDefaultMenu();
        orders = new OrderCollections();
        numCustomersServed = 0;
        numItemsOrdered = 0;
        tables= new TableCollections();
        tables.generateDefaultTableList();
        seatingStrat = new FIFOSeatingStrategy(tables);
        cookingStrat = new PrepByFIFO(orders);
        tabs = new TabCollection();
    }
    
    
    /**
     * Resets the state of the restaurant
     */
    public void resetStats(){
    	numItemsOrdered = 0;
    	numCustomersServed = 0;
    	comments = new CommentCollection();
    	tabs = new TabCollection();
    	tables.generateDefaultTableList();
    	
    }
    

    @Override
    public void addComment(Comment comment) {
        comments.addComment(comment);
    }
    
    public void addOrder(Order order){
    	orders.addOrderItem(order);
    }
    
    public OrderCollections getOrders(){
    	return orders;
    }

    @Override
    public Menu getMenu() {
        return menu;
    }

    @Override
    public CommentCollection getComments() {
        return comments;
    }
    
    public TableCollections getTables(){
    	return tables;
    }
    
    /**
     * Uses the selected seating strategy to assign
     * the given party to an open table
     * @param party party to be assigned
     * @return whether party was successfully assigned
     */
    public boolean addParty(CustomerParty party){
    	
    		if(seatingStrat.addParty(party)){
    			for(int i = 0; i < party.getSize(); i++)
    				incrementCustomersServed();
    			return true;
    		
    			
    	}
    	return false;
    }
    
    /**
     * Finds the given table where a party is seated and
     * removes the party from that table
     * @param party the party to be removed from a table
     */
    public void removeParty(CustomerParty party){
    	for(Table table: tables){
    		if (table.getCustomerParty() == party){
    			table.removeCustomerParty();
    			return;
    		}
    	}
    }
    
    public void addMenuItem(MenuItem item){
    	menu.addMenuItem(item);
    }

	public int getNumItemsOrdered() {
		return numItemsOrdered;
	}

	public void incrementNumItemsOrdered() {
		numItemsOrdered++;
	}

	public int getNumCustomersServed() {
		return numCustomersServed;
	}

	public void incrementCustomersServed() {
		numCustomersServed++;
	}
	
	public void setSeatingStrategy(I_SeatingStrategy strategy){
		
		seatingStrat = strategy;
	}

	public void setPrepStrategy(I_CookingStrategy strategy) {
		cookingStrat = strategy;
		
	}
	
	public void prepareFood(){
		cookingStrat.prepareFood();
	}


	public void removeOrders(ArrayList<Order> orders) {
		this.orders.removeOrders(orders);
		
	}
	
	public void addTab(I_Tab tab){
		tabs.addTab(tab);
	}
	
	public TabCollection getTabs(){
		return tabs;
	}
}
